/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package zblibrary.facechat.modules.school;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;

import zblibrary.facechat.R;
import zuo.biao.library.base.BaseModel;
import zuo.biao.library.base.BaseView;
import zuo.biao.library.util.CommonUtil;

public class SchoolItemView extends BaseView<School> implements OnClickListener {
	private static final String TAG = "SchoolItemView";

	public SchoolItemView(Activity context, ViewGroup parent) {
		super(context, R.layout.school_view, parent);
	}

	public ImageView iv_pic;
	public TextView tv_title;
	public TextView tv_update_time;
	public TextView fire_count;

	@SuppressLint("InflateParams")
	@Override
	public View createView() {
		iv_pic = (ImageView) findViewById(R.id.school_pic);
		tv_title = (TextView) findViewById(R.id.school_title);
		tv_update_time =  (TextView) findViewById(R.id.school_update_time);
		fire_count = (TextView) findViewById(R.id.school_fire_count);

		return super.createView();
	}

	@Override
	public void bindView(School data_){
		super.bindView(data_ != null ? data_ : new School());

		Glide.with(context).asBitmap().load(data.getPic1()).into(new SimpleTarget<Bitmap>() {
			@Override
			public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
				iv_pic.setImageBitmap(CommonUtil.toRoundCorner(bitmap, 4));
			}
		});

		tv_title.setText(data.getTitle());
		fire_count.setText(String.valueOf(2000));
	}

	@Override
	public void onClick(View v) {
		if (BaseModel.isCorrect(data) == false) {
			return;
		}
		switch (v.getId()) {
			case R.id.school_pic: {
				showShortToast("再按一次退出");
				break;
			}
			case R.id.school_title: {
				showShortToast("点击了Title");
				break;
			}
			case R.id.school_update_time: {
				showShortToast("点击了Phone");
				break;
			}
			default:
				break;
		}
	}
}